package com.indusfo.spc.controller;

import com.indusfo.spc.pojo.MatFlow;
import com.indusfo.spc.pojo.MatVer;
import com.indusfo.spc.service.MatFlowService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 熊冰
 * @Date: 2019/11/20 14:18
 */
@Controller
@RequestMapping(value = "/service/matFlow")
public class MatFlowController {
    @Autowired
    private MatFlowService matFlowService;

    /**
     * @Author 熊冰 查询
     * @Date 2019/11/25 8:54
     */

    @RequestMapping(value = "/queryMatFlow")
    @ResponseBody
    public JSONObject queryMatFlow(MatFlow matFlow) {
        JSONObject json = matFlowService.queryMatFlow(matFlow);
        return json;
    }

    /**
     * @Author 熊冰新增
     * @Date 2019/11/25 8:54
     */

    @RequestMapping(value = "/insertMatFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject insertMatFlow(MatFlow matFlow) {
        JSONObject json = matFlowService.insertMatFlow(matFlow);
        return json;
    }

    /**
     * @Author 熊冰 修改
     * @Date 2019/11/25 8:54
     */

    @RequestMapping(value = "/updateMatFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject updateMatFlow(MatFlow matFlow) {
        JSONObject json = matFlowService.updateMatFlow(matFlow);
        return json;
    }

    /**
     * @Author 熊冰 删除
     * @Date 2019/11/25 8:54
     */

    @RequestMapping(value = "/deleteMatFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject deleteMatFlow(@RequestParam("matFlowIds") List<Integer> matFlowIds, Integer dataState) {
        dataState = 2;
        JSONObject json = matFlowService.deleteMatFlow(matFlowIds, dataState);
        return json;
    }

    /**
     * 级联删除工序流程关联的工位、采集参数、关键物料、不良现象
     */
    @RequestMapping(value = "/deleteCascadeMatFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject deleteCascadeMatFlow(@RequestParam("matFlowIds") List<Integer> matFlowIds, Integer dataState) {
        dataState = 2;
        try {
            return matFlowService.deleteCascadeMatFlow(matFlowIds, dataState);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONObject.build(JSONObject.ERROR, e.getMessage(), null);
        }
    }

    /**
     * @Author 熊冰 启用/停用
     * @Date 2019/11/25 8:55
     */

    @RequestMapping(value = "/definedMatFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject definedMatFlow(@RequestParam("matFlowIds") List<Integer> matFlowIds, Integer dataState) {
        JSONObject json = matFlowService.deleteMatFlow(matFlowIds, dataState);
        return json;
    }

    /**
     * @Author 熊冰 保存流程工位
     * @Date 2019/11/23 10:34
     */
    @RequestMapping(value = "/saveMatStation", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveMatStation(@RequestBody MatFlow matFlow) {
        JSONObject json = matFlowService.saveMatStation(matFlow);
        return json;
    }

    /**
     * @Author 熊冰 保存流程采集参数
     * @Date 2019/11/23 10:34
     */
    @RequestMapping(value = "/saveMatDete", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveMatDete(@RequestBody MatFlow matFlow) {
        JSONObject json = matFlowService.saveMatDete(matFlow);
        return json;
    }

    /**
     * @Author 熊冰 保存流程关键物料
     * @Date 2019/11/23 10:34
     */
    @RequestMapping(value = "/saveMatBom", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveMatBom(@RequestBody MatFlow matFlow) {
        JSONObject json = matFlowService.saveMatBom(matFlow);
        return json;
    }

    /**
     * @Author 熊冰 保存流程不良现象
     * @Date 2019/11/23 10:34
     */
    @RequestMapping(value = "/saveMatBadpheno", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveMatBadpheno(@RequestBody MatFlow matFlow) {
        JSONObject json = matFlowService.saveMatBadpheno(matFlow);
        return json;
    }

    /**
     * 去添加查询（产品，任务单，批次）
     */
    @RequestMapping(value = "/queryListMatFlowToInsert")
    @ResponseBody
    public JSONObject queryListMatFlowToInsert(MatFlow matFlow) {
        JSONObject json = matFlowService.queryListMatFlowToInsert(matFlow);
        return json;
    }

}
